package com.mmf.web;

import com.mmf.dto.ResponseModel;
import com.mmf.model.Comment;
import com.mmf.model.GoodsDetail;
import com.mmf.model.GoodsImg;
import com.mmf.model.Page;
import com.mmf.service.ICommentService;
import com.mmf.service.IGoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by MMF on 2017-06-21.
 */
@Controller
@RequestMapping("/comment")
public class CommentController extends BaseController {
    @Resource
    private ICommentService commentService;

    /**
     * 插入一条评论
     *
     * @param comment
     * @param request
     * @return
     */
    @RequestMapping(value = "/insertComment", method = RequestMethod.POST)
    @ResponseBody
    public Object insertComment(Comment comment, MultipartHttpServletRequest request) {
        return commentService.insertComment(comment, request);
    }

    /**
     * 删除一条评论
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Object delete(Integer id) {
        return commentService.delete(id);
    }

    /**
     * 更新评论
     *
     * @param comment
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public Object insertComment(Comment comment) {
        return commentService.update(comment);
    }

    /**
     * 查找一条评论
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/find", method = RequestMethod.GET)
    @ResponseBody
    public Object find(Integer id) {
        return commentService.find(id);
    }

    /**
     * 获取评论列表
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public Object list(Integer pageNo, Integer pageSize, String userId, String goodsId) {
        Page page = new Page(request);
        return commentService.list(page,userId,goodsId);
    }

}
